﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.IO;
using System.Text;
using Tools.Utils;

namespace Tools.Service
{
    public class ImageService
    {
        /// <summary>
        /// 等比例缩放图片并保存
        /// </summary>
        /// <param name="bitmap"></param>
        /// <param name="destHeight"></param>
        /// <param name="destWidth"></param>
        /// <returns></returns>
        public void ZoomImage(Bitmap bitmap, int destHeight, int destWidth, string savePath)
        {
            ImageHelper imageHelper = new ImageHelper();
            var img = imageHelper.ZoomImage(bitmap, destHeight, destWidth);
            img.Save(savePath);
        }

        /// <summary>
        /// 图片背景透明化，并设置宽度高度
        /// </summary>
        /// <param name="bitmap">图片</param>
        /// <param name="w">宽度</param>
        /// <param name="h">高度</param>
        /// <param name="savePath">保存路径</param>
        public void ImageBackgroundTransparent(Bitmap bitmap, int w, int h, string savePath)
        {
            ImageHelper imageHelper = new ImageHelper();
            var img = imageHelper.Conver_1(bitmap, w, h);
            img.Save(savePath);
        }

        /// <summary>
        /// 图片指定颜色透明化
        /// </summary>
        /// <param name="bitmap">图片</param>
        /// <param name="w">宽度</param>
        /// <param name="h">高度</param>
        /// <param name="r"></param>
        /// <param name="g"></param>
        /// <param name="b"></param>
        /// <param name="savePath">保存路径</param>
        public void ImageBackgroundColor(Bitmap bitmap, int w, int h, int r, int g, int b, string savePath)
        {
            ImageHelper imageHelper = new ImageHelper();
            var img = imageHelper.Conver_2(bitmap, w, h, r, g, b);
            img.Save(savePath);
        }

        /// <summary>
        /// 图片替换背景色
        /// </summary>
        /// <param name="bitmap"></param>
        /// <param name="color"></param>
        /// <param name="savePath"></param>
        /// <param name="type">0-换背景色，1-背景透明</param>
        public void ImageBackgroundColor(Bitmap bitmap, string savePath, Color color, int type = 0)
        {
            ImageHelper imageHelper = new ImageHelper();
            imageHelper.Conver_3(bitmap, color.R, color.G, color.B,savePath);
            //img.Save(savePath);
        }
    }
}
